package com.iespring.controller.admin.issue;

import com.iespring.bean.admin.issue.bo.IssueCreateBO;
import com.iespring.bean.admin.issue.pojo.Issue;
import com.iespring.bean.admin.issue.vo.IssueListVo;
import com.iespring.bean.admin.issue.vo.IssueNoDeletedVO;
import com.iespring.bean.common.BasePageInfo;
import com.iespring.bean.common.BaseRespVo;
import com.iespring.service.issue.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 浩澄
 * @Date: 2022/12/29-10:40
 * @Mission: # 通用问题管理
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {

    @Autowired
    IssueService issueService;

    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info , String question){
        //不输入就是null或""

        IssueListVo issueListVo = issueService.list(info, question);

        return BaseRespVo.ok(issueListVo);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody IssueCreateBO issueCreateBO){

        IssueNoDeletedVO issueNoDeletedVO = issueService.create(issueCreateBO);

        return BaseRespVo.ok(issueNoDeletedVO);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Issue issue){

        Issue issueUpdate = issueService.update(issue);

        return BaseRespVo.ok(issueUpdate);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody IssueNoDeletedVO issueNoDeletedVO){

        int code = issueService.delete(issueNoDeletedVO);

        if (code == 200){
            return BaseRespVo.ok();
        }else {
            return BaseRespVo.error("删除问题失败",621);
        }
    }

}
